<?php

class PracticeController extends \Phalcon\Mvc\Controller {

    public function indexAction() {
        
    }

    public function doAction($part, $level) {
        $parameters = array(
            "part = '$part' AND level = '$level'",
            'order' => 'RAND()',
        );
        $questions = array();
        $question = Questions::findFirst($parameters);
        $audio = Audios::findFirstById($question->audio);
        $reference = Reference::findFirstById($question->reference);
        if ($part == 3 || $part == 4) {
            $qtList = Questions::find("part = '$part' AND level = '$level' AND audio = '$question->audio'");
            $questions = $qtList->toArray();
        } else if ($part == 6 || $part == 7) {
            $qtList = Questions::find("part = '$part' AND level = '$level' AND reference = '$question->reference'");
            $questions = $qtList->toArray();
        } else {
            array_push($questions, $question->toArray());
        }
        $this->view->audio = $audio;
        $this->view->reference = $reference;
        $this->view->questions = $questions;
    }

}
